<?php 
	include './header.php';
	//接受商品的id
	$id=$_GET['id'];
	$sql_goods="select
					g.id        gid,
					g.name      gname,
					g.is_new    gnew,
					g.is_hot    ghot,
					g.is_bast   gbast,
					g.price     gp,
					g.stock     gs,
					gi.name     giname,
					c.name      cname,
					g.addtime   gtime
				from
					goods       g,
					goods_img   gi,
					category    c
				where
					g.id=gi.goods_id
				and
					g.cate_id=c.id
				and
					gi.is_cover=1
				and
					g.id=$id
				";
	$goods_list=$goods_model->find($sql_goods)[0];
	$img_model=new Model('goods_img');
	//查看图片
	$img_sql="select `name` from `goods_img` where goods_id=$id limit 0,4";
	$goods_img=$img_model->find($img_sql);
	//var_dump($goods_img);
	if (!empty($goods_img)) 
	{
		foreach ($goods_img as $key => $value) 
		{
			$goods_img[$key]['name']=URL.'/public/uploads/'.substr($value['name'], 0,4).'/'.substr($value['name'], 4,2).'/'.substr($value['name'], 6,2).'/80_'.$value['name'];
		}
	}
?>
<div class="clear"></div>
<div id="main">
	<div class="goods">
		<div class="left">
			<img class="big" src="<?php echo URL.'/public/uploads/'.substr($goods_list['giname'], 0,4).'/'.substr($goods_list['giname'], 4,2).'/'.substr($goods_list['giname'], 6,2).'/400_'.$goods_list['giname'];?>" alt="美工回家生娃了">
			
				<ul>
					<?php foreach ($goods_img as $k => $v) :?>
						<li>
							<img class="small" width="80" height="80" src="<?php echo $v['name'];?>" alt="美工回家生娃了">
						</li>
					<?php endforeach;?>
				</ul>

		</div>

		<div class="right">
			<div class="info">
				<div class="shang">
					<span style="margin-left:20px;">商品名：</span>
					<?php echo $goods_list['gname'];?>
				</div>
				<br/>
				<div class="jia">
					<span style="margin-left:20px;">价格：</span>
					<span style="font:bold 24px/40px 宋体;color:red">￥:<?php echo $goods_list['gp'];?></span>
					<br/>
					<span style="font:12px/40px 宋体;color:#f90;margin-left:20px;">满1件7折,包邮；满2件6折,包邮</span>
					<br/>
				</div>
				
				<div class="ku">
					<span style="margin-left:20px;">库存：</span>
					 &nbsp;&nbsp;<?php echo $goods_list['gs'];?>
				<br/>			
				</div>
				<div class="fen">
					<span style="margin-left:20px;">分类：</span>
					&nbsp;&nbsp;<?php echo $goods_list['cname'];?>
					<br/>
				</div>
				
				<div class="shijian">
					<span style="margin-left:20px;">上架时间：</span>
					<?php echo date('Y年m月d日',$goods_list['gtime']);?>
					<br/>
				</div>
				
				<div class="gou">
				<form action="<?php echo URL;?>/docar.php?a=add" method="post">
					<input type="hidden" name="id" value="<?php echo $goods_list['gid'];?>">
					<span style="margin-left:20px;">购买数量：</span>
					<button onclick="return minus()" style="width:30px;">-</button>
					<input id="num" name="num" value="1" style="width:60px;height:30px;border:1px solid #A7A6AC;text-align:center;" />
					<button onclick="return plus()" style="width:30px;">+</button>
					<br/>
					<br/>
					<input type="submit" value="立即购买" style="margin-left:50px;width:100px;height:35px;border:1px solid red;background:#FFEDED;" />
					<input type="submit" value="加入购物车" style="margin-left:20px;width:100px;height:35px;border:1px solid red;background:#C40000;"/>
				</form>
				</div>
				<script type="text/javascript">
				//减法
					function minus()
					{
						var num=document.getElementById('num');
						num1=parseInt(num.value)-1;
						if (num1<=0) 
						{
							num1=1;
						};
						num.value=num1;
						return false;
					}
				//加法
					function plus()
					{
						var num=document.getElementById('num');
						num1=parseInt(num.value)+1;
						num.value=num1;
						return false;
					}
				</script>
			</div>
		</div>
		<div class="clear"></div>
	</div>
</div>
<?php 
	include PATH.'/footer.php';
?>